package com.ruoyi.controller.admin.customer;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.customer.AdminIntentionDB;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.service.admin.AdminIntentionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户意向Controller
 *
 * @author chencheng
 * @date 2025-10-07
 */
@RestController
@RequestMapping("/admin/intention")
public class AdminIntentionController extends BaseController {
    @Resource
    private AdminIntentionService adminIntentionService;

    /**
     * 查询用户意向列表
     */
    @PreAuthorize("@ss.hasPermi('customer:intention:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdminIntentionDB adminIntentionDB) {
        return adminIntentionService.selectCustomerIntentionDBList(adminIntentionDB);
    }

    /**
     * 导出用户意向列表
     */
    @PreAuthorize("@ss.hasPermi('customer:intention:export')")
    @Log(title = "用户意向", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AdminIntentionDB adminIntentionDB) {
        List<AdminIntentionDB> list = (List<AdminIntentionDB>)adminIntentionService.selectCustomerIntentionDBList(adminIntentionDB).getRows();
        ExcelUtil<AdminIntentionDB> util = new ExcelUtil<AdminIntentionDB>(AdminIntentionDB.class);
        util.exportExcel(response, list, "用户意向数据");
    }

    /**
     * 获取用户意向详细信息
     */
    @PreAuthorize("@ss.hasPermi('customer:intention:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(adminIntentionService.selectCustomerIntentionDBById(id));
    }

    /**
     * 新增用户意向
     */
    @PreAuthorize("@ss.hasPermi('customer:intention:add')")
    @Log(title = "用户意向", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdminIntentionDB adminIntentionDB) {
        return toAjax(adminIntentionService.insertCustomerIntentionDB(adminIntentionDB));
    }

    /**
     * 修改用户意向
     */
    @PreAuthorize("@ss.hasPermi('customer:intention:edit')")
    @Log(title = "用户意向", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdminIntentionDB adminIntentionDB) {
        return toAjax(adminIntentionService.updateCustomerIntentionDB(adminIntentionDB));
    }

    /**
     * 删除用户意向
     */
    @PreAuthorize("@ss.hasPermi('customer:intention:remove')")
    @Log(title = "用户意向", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(adminIntentionService.deleteCustomerIntentionDBByIds(ids));
    }

    // 已经通知客户
    @GetMapping("/isNotified/{id}")
    @PreAuthorize("@ss.hasPermi('customer:intention:edit')")
    public AjaxResult isNotified(@PathVariable Long id) {
        return toAjax(adminIntentionService.updateIsNotified(id));
    }
    // 客户购买
    @GetMapping("/isHave/{id}")
    @PreAuthorize("@ss.hasPermi('customer:intention:edit')")
    public AjaxResult isHave(@PathVariable Long id) {
        return toAjax(adminIntentionService.updateIsHave(id));
    }
}
